package com.tencent.mid.util;

public class Base64
{
  public static final int CRLF = 4;
  public static final int DEFAULT = 0;
  public static final int NO_CLOSE = 16;
  public static final int NO_PADDING = 1;
  public static final int NO_WRAP = 2;
  public static final int URL_SAFE = 8;

  static
  {
    if (!(Base64.class.desiredAssertionStatus()));
    for (int i = 1; ; i = 0)
    {
      a = i;
      return;
    }
  }

  public static byte[] decode(String paramString, int paramInt)
  {
    return decode(paramString.getBytes(), paramInt);
  }

  public static byte[] decode(byte[] paramArrayOfByte, int paramInt)
  {
    return decode(paramArrayOfByte, 0, paramArrayOfByte.length, paramInt);
  }

  public static byte[] decode(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3)
  {
    b localb = new b(paramInt3, new byte[paramInt2 * 3 / 4]);
    if (!(localb.a(paramArrayOfByte, paramInt1, paramInt2, true)))
      throw new IllegalArgumentException("bad base-64");
    if (localb.b == localb.a.length)
      return localb.a;
    paramArrayOfByte = new byte[localb.b];
    System.arraycopy(localb.a, 0, paramArrayOfByte, 0, localb.b);
    return paramArrayOfByte;
  }

  public static byte[] encode(byte[] paramArrayOfByte, int paramInt)
  {
    return encode(paramArrayOfByte, 0, paramArrayOfByte.length, paramInt);
  }

  public static byte[] encode(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3)
  {
    int j;
    c localc = new c(paramInt3, null);
    int i = paramInt2 / 3 * 4;
    if (localc.d)
    {
      paramInt3 = i;
      if (paramInt2 % 3 > 0)
        paramInt3 = i + 4;
      i = paramInt3;
      if (localc.e)
      {
        i = paramInt3;
        if (paramInt2 > 0)
        {
          j = (paramInt2 - 1) / 57;
          if (!(localc.f))
            break label186;
        }
      }
    }
    label186: for (i = 2; ; i = 1)
      while (true)
      {
        while (true)
        {
          while (true)
          {
            i = paramInt3 + i * (j + 1);
            localc.a = new byte[i];
            localc.a(paramArrayOfByte, paramInt1, paramInt2, true);
            if ((a) || (localc.b == i))
              break label192;
            throw new AssertionError();
            paramInt3 = i;
            switch (paramInt2 % 3)
            {
            case 0:
            default:
              paramInt3 = i;
            case 1:
            case 2:
            }
          }
          paramInt3 = i + 2;
        }
        paramInt3 = i + 3;
      }
    label192: return localc.a;
  }

  public static String encodeToString(byte[] paramArrayOfByte, int paramInt)
  {
    try
    {
      paramArrayOfByte = new String(encode(paramArrayOfByte, paramInt), "US-ASCII");
      return paramArrayOfByte;
    }
    catch (java.io.UnsupportedEncodingException paramArrayOfByte)
    {
      throw new AssertionError(paramArrayOfByte);
    }
  }

  public static String encodeToString(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3)
  {
    try
    {
      paramArrayOfByte = new String(encode(paramArrayOfByte, paramInt1, paramInt2, paramInt3), "US-ASCII");
      return paramArrayOfByte;
    }
    catch (java.io.UnsupportedEncodingException paramArrayOfByte)
    {
      throw new AssertionError(paramArrayOfByte);
    }
  }
}